import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { SGuildShopItem } from "../../../../../Message/Game/SGuildShopItem";
import { ItemData } from "../../../resource/info/ItemData";
import { ColorConfig } from "../../../resource/ColorConfig";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { ObjCreate } from "../../common/ObjCreate";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { Language } from "../../../../../extend/language/Language";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { GuildShopOper } from "./GuildShopOper";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { GuildEventName } from "../GuildEventName";
import { CursorManager } from "../../../manager/CursorManager";
import { GTextInput } from "../../../../../com/mui/controls/GTextInput";
import { TItem } from "../../../../../Message/Db/Tables/TItem";
import { ColorInfo } from "../../../resource/info/ColorInfo";
//class GuildShopItemRender
    
    export  class GuildShopItemRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this.init();
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onItemClickHandler);
            this.doubleClickEnabled = true;
            this.addEventListener(flash.events.MouseEvent.MOUSE_OVER, this.onMouseOver);
            this.addEventListener(flash.events.MouseEvent.MOUSE_OUT, this.onMouseOut);
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            super.data = arg1;
            this._shopItem = arg1 as SGuildShopItem;
            if (this._shopItem) 
            {
                loc1 = new ItemData(this._shopItem.itemCode);
                this._propItem.itemData = loc1;
                this._item = loc1.itemInfo.item;
                this._colorInfo = ColorConfig.instance.getItemColor(this._item.color);
                if (this._colorInfo) 
                {
                    this._colorName = this._colorInfo.color;
                }
                this._nameTxt.htmlText = HTMLUtil.addColor(this._item.name, this._colorName);
                this._remainAmountTxt.text = this._shopItem.leftAmount.toString();
                this._priceTxt.text = this._shopItem.price.toString();
                this._limitAmountTxt.text = this._shopItem.buyLimit.toString();
            }
            return;
        }

        /* internal  */init(): void
        {
            this._bgBitmap = ObjCreate.createBg(0, 0, 127, 45, this);
            ObjCreate.createBg(2, 3, 38, 38, this, ImagesConst.PackItemBg);
            this._propItem = new BaseItem();
            this._propItem.setSize(36, 36);
            this._propItem.move(3, 4);
            this.addChild(this._propItem);
            this._nameTxt = ObjCreate.createTextField("", 46, 6, 220, 20, this);
            ObjCreate.createTextField(Language.getString(57234), 130, 3, 100, 20, this, GlobalStyle.textFormat5);
            this._remainAmountTxt = ObjCreate.createGTextInput(190, 0, 80, 20, this);
            this._remainAmountTxt.textField.selectable = false;
            this._remainAmountTxt.enabled = false;
            ObjCreate.createTextField(Language.getString(57235), 46, 26, 100, 20, this);
            this._priceTxt = ObjCreate.createTextField("", 82, 26, 220, 20, this);
            ObjCreate.createTextField(Language.getString(57236), 130, 29, 100, 20, this, new GTextFormat(FontUtil.songtiName, 12, 16680960));
            this._limitAmountTxt = ObjCreate.createGTextInput(190, 26, 80, 20, this);
            this._limitAmountTxt.editable = false;
            this._limitAmountTxt.textField.selectable = false;
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            super.selected = arg1;
            if (arg1 && this._shopItem) 
            {
                this._bgBitmap.filters = [new Object /* flash.filters.GlowFilter */(3856353, 1, 6, 6, 1, 1, false, false)];
            }
            else 
            {
                this._bgBitmap.filters = [];
            }
            return;
        }

        /* internal  */onItemClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (GuildShopOper.isBuy) 
            {
                Dispatcher.dispatchEvent(new DataEvent(GuildEventName.ShopItemClick, this._shopItem, false, true));
            }
            return;
        }

        /* internal  */onMouseOver(arg1: Object /* flash.events.MouseEvent */): void
        {
            if (GuildShopOper.isBuy) 
            {
                CursorManager.showCursor(CursorManager.BUY);
            }
            return;
        }

        /* internal  */onMouseOut(arg1: Object /* flash.events.MouseEvent */): void
        {
            CursorManager.hideCursor();
            return;
        }

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_priceTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_remainAmountTxt: GTextInput;

        /* internal */ /* var */_limitAmountTxt: GTextInput;

        /* internal */ /* var */_propItem: BaseItem;

        /* internal */ /* var */_bgBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_shopItem: SGuildShopItem;

        /* internal */ /* var */_item: TItem;

        /* internal */ /* var */_colorInfo: ColorInfo;

        /* internal */ /* var */_colorName: string;
    }
